# Copyright (c) 2009 Marshall Vandegrift
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

COUNT_0OP = 0
COUNT_1OP = 1
COUNT_2OP = 2
COUNT_VAR = 4
COUNT_EXT = 5

BRANCH = 0x1
RESULT = 0x2
BYREF = 0x4
PACK1 = 0x8
RELATIVE = 0x10
REVERSE = 0x20
INVERT = 0x40

OPCODES = [ [ 'add',              COUNT_2OP,  20,    RESULT          ],
            [ 'and',              COUNT_2OP,  9,     RESULT          ],
            [ 'art_shift',        COUNT_EXT,  3,     RESULT          ],
            [ 'buffer_mode',      COUNT_VAR,  242,   0               ],
            [ 'call_1n',          COUNT_1OP,  143,   PACK1           ],
            [ 'call_1s',          COUNT_1OP,  136,   RESULT | PACK1  ],
            [ 'call_2n',          COUNT_2OP,  26,    PACK1           ],
            [ 'call_2s',          COUNT_2OP,  25,    RESULT | PACK1  ],
            [ 'call_vn',          COUNT_VAR,  249,   PACK1           ],
            [ 'call_vs',          COUNT_VAR,  224,   RESULT | PACK1  ],
            [ 'call_vn2',         COUNT_VAR,  250,   PACK1           ],
            [ 'call_vs2',         COUNT_VAR,  236,   RESULT | PACK1  ],
            [ 'catch',            COUNT_0OP,  185,   RESULT          ],
            [ 'check_arg_count',  COUNT_VAR,  255,   BRANCH          ],
            [ 'check_arg_count!', COUNT_VAR,  255,   BRANCH | INVERT ],
            [ 'check_unicode',    COUNT_EXT,  12,    RESULT          ],
            [ 'clear_attr',       COUNT_2OP,  12,    0               ],
            [ 'copy_table',       COUNT_VAR,  253,   0               ],
            [ 'dec',              COUNT_1OP,  134,   BYREF           ],
            [ 'decjl',            COUNT_2OP,  4,     BRANCH | BYREF  ],
            [ 'decjge',           COUNT_2OP,  4,     BRANCH | BYREF | INVERT ],
            [ 'div',              COUNT_2OP,  23,    RESULT          ],
            [ 'draw_picture',     COUNT_EXT,  5,     0               ],
            [ 'encode_text',      COUNT_VAR,  252,   0               ],
            [ 'erase_line',       COUNT_VAR,  238,   0               ],
            [ 'erase_picture',    COUNT_EXT,  7,     0               ],
            [ 'erase_window',     COUNT_VAR,  237,   0               ],
            [ 'get_child',        COUNT_1OP,  130,   RESULT | BRANCH ],
            [ 'get_child!',       COUNT_1OP,  130,   RESULT | BRANCH | INVERT ],
            [ 'get_cursor',       COUNT_VAR,  240,   0               ],
            [ 'get_next_prop',    COUNT_2OP,  19,    RESULT          ],
            [ 'get_parent',       COUNT_1OP,  131,   RESULT          ],
            [ 'get_prop',         COUNT_2OP,  17,    RESULT          ],
            [ 'get_prop_addr',    COUNT_2OP,  18,    RESULT          ],
            [ 'get_prop_len',     COUNT_1OP,  132,   RESULT          ],
            [ 'get_sibling',      COUNT_1OP,  129,   RESULT          ],
            [ 'get_wind_prop',    COUNT_EXT,  19,    RESULT          ],
            [ 'inc',              COUNT_1OP,  133,   BYREF           ],
            [ 'incjg',            COUNT_2OP,  5,     BRANCH | BYREF  ],
            [ 'incjle',           COUNT_2OP,  5,     BRANCH | BYREF | INVERT ],
            [ 'input_stream',     COUNT_VAR,  244,   0               ],
            [ 'insert_obj',       COUNT_2OP,  14,    0               ],
            [ 'je',               COUNT_2OP,  1,     BRANCH          ],
            [ 'jne',              COUNT_2OP,  1,     BRANCH | INVERT ],
            [ 'jg',               COUNT_2OP,  3,     BRANCH          ],
            [ 'jle',              COUNT_2OP,  3,     BRANCH | INVERT ],
            [ 'jin',              COUNT_2OP,  6,     BRANCH          ],
            [ 'jnin',             COUNT_2OP,  6,     BRANCH | INVERT ],
            [ 'jl',               COUNT_2OP,  2,     BRANCH          ],
            [ 'jge',              COUNT_2OP,  2,     BRANCH | INVERT ],
            [ 'jump',             COUNT_1OP,  140,   RELATIVE        ],
            [ 'jz',               COUNT_1OP,  128,   BRANCH          ],
            [ 'jnz',              COUNT_1OP,  128,   BRANCH | INVERT ],
            [ 'load',             COUNT_1OP,  142,   RESULT | BYREF  ],
            [ 'loadb',            COUNT_2OP,  16,    RESULT          ],
            [ 'loadw',            COUNT_2OP,  15,    RESULT          ],
            [ 'log_shift',        COUNT_EXT,  2,     RESULT          ],
            [ 'make_menu',        COUNT_EXT,  27,    BRANCH          ],
            [ 'make_menu!',       COUNT_EXT,  27,    BRANCH | INVERT ],
            [ 'mod',              COUNT_2OP,  24,    RESULT          ],
            [ 'mouse_window',     COUNT_EXT,  23,    0               ],
            [ 'move_window',      COUNT_EXT,  16,    0               ],
            [ 'mul',              COUNT_2OP,  22,    RESULT          ],
            [ 'new_line',         COUNT_0OP,  187,   0               ],
            [ 'nop',              COUNT_0OP,  180,   0               ],
            [ 'not',              COUNT_VAR,  248,   RESULT          ],
            [ 'or',               COUNT_2OP,  8,     RESULT          ],
            [ 'output_stream',    COUNT_VAR,  243,   0               ],
            [ 'picture_data',     COUNT_EXT,  6,     BRANCH          ],
            [ 'picture_data!',    COUNT_EXT,  6,     BRANCH | INVERT ],
            [ 'picture_table',    COUNT_EXT,  28,    0               ],
            [ 'piracy',           COUNT_0OP,  191,   BRANCH          ],
            [ 'piracy!',          COUNT_0OP,  191,   BRANCH | INVERT ],
            [ 'pop',              COUNT_0OP,  185,   0               ],
            [ 'pop_stack',        COUNT_EXT,  21,    0               ],
            [ 'print_addr',       COUNT_1OP,  135,   0               ],
            [ 'print_char',       COUNT_VAR,  229,   0               ],
            [ 'print_form',       COUNT_EXT,  26,    0               ],
            [ 'print_num',        COUNT_VAR,  230,   0               ],
            [ 'print_obj',        COUNT_1OP,  138,   0               ],
            [ 'print_paddr',      COUNT_1OP,  141,   PACK1           ],
            [ 'print_ret',        COUNT_0OP,  179,   0               ],
            [ 'print_table',      COUNT_VAR,  254,   0               ],
            [ 'print_unicode',    COUNT_EXT,  11,    0               ],
            [ 'pull',             COUNT_VAR,  233,   BYREF           ],
            [ 'push',             COUNT_VAR,  232,   0               ],
            [ 'push_stack',       COUNT_EXT,  24,    BRANCH          ],
            [ 'push_stack!',      COUNT_EXT,  24,    BRANCH | INVERT ],
            [ 'put_prop',         COUNT_VAR,  227,   0               ],
            [ 'put_wind_prop',    COUNT_EXT,  25,    0               ],
            [ 'quit',             COUNT_0OP,  186,   0               ],
            [ 'random',           COUNT_VAR,  231,   RESULT          ],
            [ 'read',             COUNT_VAR,  228,   RESULT          ],
            [ 'read_char',        COUNT_VAR,  246,   RESULT          ],
            [ 'read_mouse',       COUNT_EXT,  22,    0               ],
            [ 'remove_obj',       COUNT_1OP,  137,   0               ],
            [ 'restart',          COUNT_0OP,  183,   0               ],
            [ 'restore',          COUNT_EXT,  1,     RESULT          ],
            [ 'restore_undo',     COUNT_EXT,  10,    RESULT          ],
            [ 'ret',              COUNT_1OP,  139,   0               ],
            [ 'ret_popped',       COUNT_0OP,  184,   0               ],
            [ 'rfalse',           COUNT_0OP,  177,   0               ],
            [ 'rtrue',            COUNT_0OP,  176,   0               ],
            [ 'save',             COUNT_EXT,  0,     RESULT          ],
            [ 'save_undo',        COUNT_EXT,  9,     RESULT          ],
            [ 'scan_table',       COUNT_VAR,  247,   RESULT          ],
            [ 'scroll_window',    COUNT_EXT,  20,    0               ],
            [ 'set_attr',         COUNT_2OP,  11,    0               ],
            [ 'set_colour',       COUNT_2OP,  27,    0               ],
            [ 'set_cursor',       COUNT_VAR,  239,   0               ],
            [ 'set_font',         COUNT_EXT,  4,     RESULT          ],
            [ 'set_margins',      COUNT_EXT,  8,     0               ],
            [ 'set_text_style',   COUNT_VAR,  241,   0               ],
            [ 'set_window',       COUNT_VAR,  235,   0               ],
            [ 'show_status',      COUNT_0OP,  188,   0               ],
            [ 'sound_effect',     COUNT_VAR,  245,   0               ],
            [ 'split_window',     COUNT_VAR,  234,   0               ],
            [ 'store',            COUNT_2OP,  13,    BYREF | REVERSE ],
            [ 'storeb',           COUNT_VAR,  226,   0               ],
            [ 'storew',           COUNT_VAR,  225,   0               ],
            [ 'sub',              COUNT_2OP,  21,    RESULT          ],
            [ 'test',             COUNT_2OP,  7,     BRANCH          ],
            [ 'test!',            COUNT_2OP,  7,     BRANCH | INVERT ],
            [ 'test_attr',        COUNT_2OP,  10,    BRANCH          ],
            [ 'test_attr!',       COUNT_2OP,  10,    BRANCH | INVERT ],
            [ 'throw',            COUNT_2OP,  28,    0               ],
            [ 'tokenise',         COUNT_VAR,  251,   0               ],
            [ 'verify',           COUNT_0OP,  189,   BRANCH          ],
            [ 'verify!',          COUNT_0OP,  189,   BRANCH | INVERT ],
            [ 'window_size',      COUNT_EXT,  17,    0               ],
            [ 'window_style',     COUNT_EXT,  18,    0               ] ]
